package com.bjpowernode.service.impl;

import com.bjpowernode.dao.UserDao;
import com.bjpowernode.service.UserService;
import com.bjpowernode.user.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserDao userDao;

    @Override
    public int addUser(User user) {
        User resUser = userDao.selectUser(user.getUsername());
        if (resUser == null){
            return userDao.insertUser(user);
        }
        return 0;
    }

    @Override
    public boolean loginUser(User user) {
        User resUser = userDao.selectUser(user.getUsername());
        if (resUser == null){
            return false;
        }
        if (!resUser.getPassword().equals(user.getPassword())){
            return false;
        }
        return true;
    }

    @Override
    public List<User> findSomeUser(String someName) {
        return userDao.selectSomeUser(someName);
    }

    @Override
    public List<User> findFans(String username) {
        return userDao.selectFans(username);
    }

    @Override
    public User loadUser(String username) {
        return userDao.selectUser(username);
    }
}
